<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/operatehistory.jsp"%>
<%@ include file="/common/code.jsp"%>
<%@ include file="/common/user.jsp"%>
<%
    // 关注科室医生
	String code = input.getDesc("code", "").trim();
	Integer authorize = input.getInt("authorize", -1);
	User self = userByUid(token.getUid());
	if (self == null || self.getType().equals(USER_EMPLOYEE)) {
		 Tools.encryptPrint(out, new Message(30041, "您暂时不可以关注医生"));
		 return;
	}
	OperateHistory oh = OperateHistory.fromMap(parameters, OperateHistory.class);
	OperateHistory ohAuthReport = OperateHistory.fromMap(parameters, OperateHistory.class);
	// 扫描二维码形式
	if (!code.equals("")) {
		Message codeMsg = decodeQrCode(code);
		if (codeMsg.getErrcode() != 0) {
			Tools.encryptPrint(out, codeMsg);
			return;
		} 
		Map codeMap = (Map)codeMsg.get("code");
		String type = Tools.getDesc(codeMap.get("type"));
		String id = Tools.getDesc(codeMap.get("id"));
		oh.setOid(id);	
		ohAuthReport.setOid(id);
	}
    oh.setUid(token.getUid() + "");
    oh.setCategory(SECTION_DOCTOR);
    oh.setOperate(ATTENTION);
	ohAuthReport.setUid(token.getUid() + "");
	ohAuthReport.setCategory(SECTION_DOCTOR);
	ohAuthReport.setOperate(AUTH_REPORT);
	OperateHistory ohDept = OperateHistory.fromMap(parameters, OperateHistory.class);
	ohDept.setUid(token.getUid() + "");
    ohDept.setCategory(DEPT_CATEGORY);
    ohDept.setOperate(ATTENTION);
	List<String> list = QBuilder.db("basedb").select("concat(h.id, '')").from("User as u, Hospital as h").where(new Where("h.hospital=u.deptId").and("u.id=", oh.getOid())).query().getResultObj();
	if (!isEmpty(list)) {
		ohDept.setOid(list.get(0));	
		operate(ohDept, false);
	}
	User user = userByUid(Tools.getInt(oh.getOid()));
	if (user == null || Tools.getDesc(user.getJson("role")).equals("2") ) {
		 Tools.encryptPrint(out, new Message(30041, "只能关注医生"));
		 return;
	}
	Integer type = user.getType();
	if (USER_PATIENT.equals(type))
		oh.setCategory(SECTION_PATIENT);
	if (authorize == 1)
		operate(ohAuthReport, false);
    Tools.encryptPrint(out, operate(oh, false));
%>
